/*
 * HtmlTools.h
 *
 *  Created on: Mar 21, 2014
 *      Author: xy124
 *
 *  contains many useful helperfunctions for html-output
 */

#ifndef HTMLTOOLS_H_
#define HTMLTOOLS_H_

#include <string>
#include <initializer_list>
#include "utils.h"
#include "TSingleton.h"

class HtmlTools :
	public TSingleton<HtmlTools> {
public:
	HtmlTools();
	virtual ~HtmlTools();

	std::string generateTableHead();
	std::string generateTableFoot();

	// induction stop kinda like in haskell ^__^
	template<typename T>
	std::string generateCols(T t)
	{
		std::string strT= "";

			try {
				strT= toString(t);
			} catch (...) {
				mLog("could not convert col to string.");
				return "<td></td>";
			}
		// should work since http://en.wikipedia.org/wiki/Variadic_template
			return std::string("<td>") + strT + "</td>";
	}

	template<typename T, typename... Args>
	std::string generateCols(T t, Args... args)
	{
	// should work since http://en.wikipedia.org/wiki/Variadic_template
		return std::string("<td>") + generateCols(t) + "</td>" + generateCols(args...);
	}


	template<typename... Args>
	std::string generateRow(Args... args)
	{
		return "<tr>" + generateCols(args...) + "</tr>";
	}



};

#define g_phTls HtmlTools::get()
#define g_pHtmlTools HtmlTools::get()

#endif /* HTMLTOOLS_H_ */
